import requests
from bs4 import BeautifulSoup
import os
# if not os.path.exists('../ysj'):
#     os.mkdir('../images')

BASE_URL = "https://www.ddyucshu.cc"

url = 'https://www.ddyucshu.cc/0_657'
headers ={
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0'
}
response = requests.get(url, headers=headers).text
soup = BeautifulSoup(response,'lxml')
dd_list = soup.select('#list dd')
del dd_list[:6]
fp = open('fiction_ysj.txt', 'w', encoding='utf-8')
for dd in dd_list:
    title = dd.a.string
    detail = BASE_URL+dd.a['href']
    de_response = requests.get(detail, headers=headers).text
    de_soup = BeautifulSoup(de_response,'lxml')
    content_div = de_soup.find('div', id='content')
    content = content_div.text
    fp.write(title+':\n'+''+content+'\n\n\n\n\n')
    print(title,'下载完成')
fp.close()
print("全部下载完成")



